role=$(word 1,${MAKECMDGOALS})
roleCmd=$(word 2,${MAKECMDGOALS})
special=$(findstring $(role),help)

R=xxx:5000

define cmd_image =
mvn compile -DskipTests jib:build -Djib.to.image=${R}/app1
endef

define cmd_build =
mvn compile -DskipTests
endef

define cmd_install =
mvn install -DskipTests
endef

define cmd_test =
mvn test -DskipTests
endef

define cmd_deploy =
mvn install deploy -DskipTests
endef

define cmd_clean =
mvn clean -DskipTests
endef

ifeq ($(special),$(role))
.PHONY:default
default:
	@echo "role is null"

help:
	@echo help info
else

ifneq (${roleCmd},)
.PHONY:${role}
${role}:
	@if [ ! -d "${CURDIR}/${role}" ];then \
	   echo "dir ${role} is not exists"; \
	   exit 1; \
	fi

.PHONY:${roleCmd}
${roleCmd}:
	cd ${role} && $(call cmd_${roleCmd})

else

.PHONY:${role}
${role}:
ifeq (${role},image)
	find ./ -name Makefile | grep -v "\./pom.xml" | while read line; do \
	  dirName=`dirname $$line`; \
	  cd $$dirName && $(call cmd_${role}); \
	done
else
	$(call cmd_${role})
endif

endif #roleCmd null check


endif #special cmd





